package com.haois.component.util.jfree;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.DatasetRenderingOrder;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.renderer.category.StandardBarPainter;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities;

import java.awt.*;
import java.io.File;
import java.io.FileOutputStream;
import java.text.DecimalFormat;

/**
 * JFreeChart 生成图片工具
 *
 * @author RuiHaoZ on Hgits.cn
 * @date 2018/8/16 11:02
 */
public class JFreeChartUtil {
    private String CHART_PATH;

    public JFreeChartUtil(String CHART_PATH) {
        this.CHART_PATH = CHART_PATH;
    }
    //    纵轴(RangeAxis)和横轴(DomainAxis)


    // 设置面板字体
    Font labelFont = new Font("宋体", Font.TRUETYPE_FONT, 12);


    public String buildBarChart(CategoryDataset dataSet, String chartTitle, String xName,
                                String yName, String charName) {
        return buildBarChart(dataSet, chartTitle, xName, yName, charName, false);
    }

    /**
     * 生成柱形图
     * 普通柱形图，二维数据[2][3] 表示一组 2根柱子 共3组
     *
     * @param dataSet    数据集
     * @param chartTitle 表标题
     * @param xName      x轴名称
     * @param yName      y轴名称
     * @param charName   图标图片名
     * @param isMixture  是否增加折线
     * @return 图片保存地址
     */
    public String buildBarChart(CategoryDataset dataSet, String chartTitle, String xName,
                                String yName, String charName, boolean isMixture) {
        JFreeChart chart = this.buildChart(dataSet, chartTitle, xName, yName, isMixture);
        return saveFile(charName, chart);
    }

    /**
     * 折线图
     *
     * @param dataSet    数据集
     * @param chartTitle 表标题
     * @param xName      x轴名称
     * @param yName      y轴名称
     * @param charName   本地文件名
     * @return 图片保存地址
     */
    public String buildLineChar(CategoryDataset dataSet, String chartTitle, String xName, String yName,
                                String charName) {
        JFreeChart chart = this.buildLineChar(dataSet, chartTitle, xName, yName);
        return saveFile(charName, chart);
    }

    /**
     * @param data       数据集
     * @param rowKeys    目录轴的显示标签
     * @param columnKeys 数值轴的显示标签
     * @param monthEnd   本年度截止月份
     * @param unit       整体除单位 如亿元
     * @return 获取DataSet数据集合
     */
    public CategoryDataset getBarData(int monthEnd, int unit, double[][] data, Comparable<String>[] rowKeys, String[] columnKeys) {
        double[][] dou = {};
        for (int i = 0; i < dou.length; i++) {
            for (int j = 0; j < dou[i].length; j++) {
                dou[i][j] = data[i][j] / unit;
            }
        }
        return getBarData(dou, rowKeys, columnKeys);
    }
    public CategoryDataset getBarData(double[][] data, Comparable<String>[] rowKeys, String[] columnKeys) {
        return DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);
    }

    public CategoryDataset getBarData(int monthEnd, double[][] data, Comparable<String>[] rowKeys, String[] columnKeys) {
        return getBarData(monthEnd, 1, data, rowKeys, columnKeys);
    }

    /**
     * 第一数据源为柱形第二数据源为折线
     * 柱形对应左边Y轴，折线对应右边Y轴
     *
     * @param dataSet    数据源
     * @param chartTitle 表标题
     * @param xName      X轴名称
     * @param yName      左边Y轴名称
     * @param charName   文件名
     * @param dataSet2   数据源2 对应右边Y轴刻度
     * @param y2Name     右边Y轴名称
     * @return 文件保存地址
     */
    public String buildPairYMixtureChart(CategoryDataset dataSet, String chartTitle, String xName,
                                         String yName, String charName, CategoryDataset dataSet2, String y2Name) {
        JFreeChart chart = this.buildChart(dataSet, chartTitle, xName, yName, false);

        Color color = new Color(192, 0, 0);
        NumberAxis axis2 = getNumberAxis2(y2Name, color);


        LineAndShapeRenderer lineAndShapeRenderer = new LineAndShapeRenderer();
        setLineRenderer(lineAndShapeRenderer);
//        lineAndShapeRenderer.setSeriesPaint(0, color);

        //增加新的数据源，和原数据是重合在统一地方的
        CategoryPlot categoryPlot = chart.getCategoryPlot();
        categoryPlot.setRangeAxis(1, axis2);
        categoryPlot.setDataset(1, dataSet2);
        categoryPlot.setRenderer(1, lineAndShapeRenderer);
        //将数据源index绑定在坐标轴axisIndex上
        categoryPlot.mapDatasetToRangeAxis(1, 1);
        categoryPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

        return saveFile(charName, chart);
    }

    /**
     * 曲线救国，设置一组柱形对应两个不同的Y轴
     * 双柱形对应双Y轴，实质为两个数据源，但看起来和一个数据源的图一样
     * 第一数据源应为 [0][1]无数据 第二数据源英文 [0][0]无数据
     *
     * @param dataSet    数据源
     * @param chartTitle 表标题
     * @param xName      X轴名称
     * @param yName      左边Y轴名称
     * @param charName   文件名
     * @param dataSet2   数据源2 对应右边Y轴刻度
     * @param y2Name     右边Y轴名称
     * @return 文件保存地址
     */
    public String buildPairYMixtureChart2(CategoryDataset dataSet, String chartTitle, String xName,
                                          String yName, String charName, CategoryDataset dataSet2, String y2Name) {
        JFreeChart chart = this.buildChart(dataSet, chartTitle, xName, yName, false);

        Color color = new Color(192, 0, 0);
        NumberAxis axis2 = getNumberAxis2(y2Name, color);


        BarRenderer barRenderer = new BarRenderer();
        setBarRenderer(barRenderer);
        barRenderer.setItemMargin(0.005);
        barRenderer.setSeriesItemLabelsVisible(0, false);

        //增加新的数据源，和原数据是重合在统一地方的
        CategoryPlot categoryPlot = chart.getCategoryPlot();
        categoryPlot.setRangeAxis(1, axis2);
        categoryPlot.setDataset(1, dataSet2);
        categoryPlot.setRenderer(1, barRenderer);
        //将数据源index绑定在坐标轴axisIndex上
        categoryPlot.mapDatasetToRangeAxis(1, 1);
        categoryPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

        categoryPlot.getRenderer(0).setSeriesItemLabelsVisible(1, false);
        categoryPlot.getRenderer(1).setSeriesItemLabelsVisible(0, false);


        return saveFile(charName, chart);
    }

    /**
     * 生成折线图
     *
     * @param dataSet    数据集
     * @param chartTitle 图标题
     * @param xName      x轴名称
     * @param yName      y轴名称
     * @return 折线图保存路径
     */
    private JFreeChart buildLineChar(CategoryDataset dataSet, String chartTitle, String xName, String yName) {
        setChartTheme();
        JFreeChart chart = ChartFactory.createLineChart(chartTitle, xName, yName,
                dataSet, PlotOrientation.VERTICAL, true, true, false);

        chart.setTextAntiAlias(false);
        chart.setBackgroundPaint(Color.WHITE);

        TextTitle title = new TextTitle(chartTitle);
        // 设置图标题的字体重新设置title
        chart.setTitle(title);
        chart.setBackgroundPaint(Color.WHITE);
        CategoryPlot categoryPlot = (CategoryPlot) chart.getPlot();
        setCategoryPlotBlack(categoryPlot);

        // 设置轴和面板之间的距离
//         categoryPlot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

        // y轴设置
        setValueAxis(categoryPlot);
        setNumberAxis(categoryPlot);
        setCategoryAxis(categoryPlot);

        // 获得renderer 注意这里是下放造型到 LineAndShapeRenderer！！
        LineAndShapeRenderer lineAndShapeRenderer = (LineAndShapeRenderer) categoryPlot.getRenderer();
//        LineAndShapeRenderer lineAndShapeRenderer = new LineAndShapeRenderer();
        lineAndShapeRenderer = setLineRenderer(lineAndShapeRenderer);
        lineAndShapeRenderer.setSeriesStroke(0, new BasicStroke(2F));
        lineAndShapeRenderer.setSeriesStroke(1, new BasicStroke(2F));
        return chart;

    }

    /**
     * 生成折线图和柱形图的混合
     *
     * @param dataSet    数据集
     * @param chartTitle 图标题
     * @param xName      x轴名称
     * @param yName      y轴名称
     * @param charName   折线图图片名称
     * @return 混合图保存路径
     */
    public String buildMixtureChar(CategoryDataset dataSet, String chartTitle, String xName, String yName,
                                   String charName) {
        setChartTheme();

        JFreeChart chart = ChartFactory.createBarChart3D(chartTitle, xName, yName,
                dataSet, PlotOrientation.VERTICAL, true, true, false);
        //获取图表区域对象
        CategoryPlot categoryPlot = (CategoryPlot) chart.getPlot();

        setCategoryPlotBlack(categoryPlot);
        setNumberAxis(categoryPlot);
        setValueAxis(categoryPlot);
        setCategoryAxis(categoryPlot);

        categoryPlot.setForegroundAlpha(0.85f);

        BarRenderer barRenderer = (BarRenderer) categoryPlot.getRenderer();
        //设置柱形图的宽度
        barRenderer.setMaximumBarWidth(0.07);
        //在图形上显示数字
        barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        barRenderer.setBaseItemLabelsVisible(true);
        barRenderer.setShadowVisible(false);
        barRenderer.setIncludeBaseInRange(true);
        // 设置柱的颜色
        barRenderer.setSeriesPaint(0, new Color(79, 129, 189));
        barRenderer.setSeriesPaint(1, new Color(192, 0, 0));
        // 设置每个地区所包含的平行柱的之间距离
        barRenderer.setItemMargin(0.0);
        categoryPlot.setDataset(1, dataSet);
        //设置折线
     /*   JFreeChart chart = buildChart(dataSet,chartTitle,xName,yName,charName,true);
        CategoryPlot categoryPlot = chart.getCategoryPlot();
        categoryPlot.setDataset(1, dataSet);*/

        LineAndShapeRenderer lineAndShapeRenderer = new LineAndShapeRenderer();
        lineAndShapeRenderer = setLineRenderer(lineAndShapeRenderer);
        lineAndShapeRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        lineAndShapeRenderer.setBaseItemLabelsVisible(true);
        lineAndShapeRenderer.setSeriesStroke(0, new BasicStroke(2F));
        lineAndShapeRenderer.setSeriesStroke(1, new BasicStroke(2F));


        //设置某坐标轴索引上数据集的显示样式
        categoryPlot.setRenderer(1, lineAndShapeRenderer);
        // 设置两个图的前后顺序
        // DatasetRenderingOrder.FORWARD表示后面的图在前者上面，DatasetRenderingOrder.REVERSE表示 表示后面的图在前者后面
        categoryPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

        return saveFile(charName, chart);
    }

    /**
     * 设置字体，防止乱码
     */
    private StandardChartTheme setChartTheme() {
        StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
        //设置标题字体
        standardChartTheme.setExtraLargeFont(new Font("幼圆", Font.BOLD, 20));
        //设置图例的字体
        standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 15));
        //设置轴向的字体
        standardChartTheme.setLargeFont(new Font("黑体", Font.PLAIN, 15));
        //应用主题样式
        ChartFactory.setChartTheme(standardChartTheme);
        return standardChartTheme;
    }

    /**
     * 设置y轴 数据轴精度(通用，可自行覆盖改配置)
     *
     * @param plot 柱状图队形
     */
    private NumberAxis setNumberAxis(CategoryPlot plot) {
        // 数据轴精度
        NumberAxis vn = (NumberAxis) plot.getRangeAxis();
        // 数据轴数据标签的显示格式
        DecimalFormat df = new DecimalFormat("#0");
        vn.setNumberFormatOverride(df);
        //原折线图
        vn.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        vn.setAutoRangeIncludesZero(true);
        return vn;
    }


    /**
     * 设置x坐标样式(通用，可自行覆盖改配置)
     *
     * @param plot 柱状图队形
     */
    private CategoryAxis setCategoryAxis(CategoryPlot plot) {
        CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setLabelFont(labelFont);// 轴标题
        domainAxis.setTickLabelFont(labelFont);// 轴数值
        // Lable（Math.PI/3.0）度倾斜
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 3.0));
        // 横轴上的 Lable 是否完整显示
        domainAxis.setMaximumCategoryLabelWidthRatio(1.0f);
        // 设置距离图片左端距离
        domainAxis.setLowerMargin(0.02);
        // 设置距离图片右端距离
        domainAxis.setUpperMargin(0.02);
        // 横轴上的
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
        plot.setDomainAxis(domainAxis);
        return domainAxis;
    }

    /**
     * 设置y轴样式(通用，可自行覆盖改配置)
     *
     * @param plot 柱状图队形
     */
    private ValueAxis setValueAxis(CategoryPlot plot) {
        // y轴设置
        ValueAxis rangeAxis = plot.getRangeAxis();
        rangeAxis.setLabelFont(labelFont);
        rangeAxis.setTickLabelFont(labelFont);
        // 设置最高的一个 Item 与图片顶端的距离
        rangeAxis.setUpperMargin(0.15);
        // 设置最低的一个 Item 与图片底端的距离
        rangeAxis.setLowerMargin(0.15);
        plot.setRangeAxis(rangeAxis);
        return rangeAxis;
    }

    /**
     * 设置数据区背景
     *
     * @param plot 柱状图队形
     */
    private CategoryPlot setCategoryPlotBlack(CategoryPlot plot) {
        // 设置横虚线可见
        plot.setRangeGridlinesVisible(true);
        // 虚线色彩
        plot.setRangeGridlinePaint(Color.gray);
        plot.setBackgroundPaint(new Color(255, 255, 255));
        // x轴 // 分类轴网格是否可见
        plot.setDomainGridlinesVisible(true);
        // y轴 //数据轴网格是否可见
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.gray);// 虚线色彩
        plot.setDomainGridlinePaint(Color.gray);// 虚线色彩
        return plot;
    }


    /**
     * @param lineAndShapeRenderer 折线图 线条
     * @return 设置样式
     */
    private LineAndShapeRenderer setLineRenderer(LineAndShapeRenderer lineAndShapeRenderer) {

        lineAndShapeRenderer.setSeriesStroke(0, new BasicStroke(1F));
        lineAndShapeRenderer.setSeriesStroke(1, new BasicStroke(1F));
        lineAndShapeRenderer.setSeriesPaint(0, new Color(79, 129, 189));
        lineAndShapeRenderer.setSeriesPaint(1, new Color(192, 0, 0));
        lineAndShapeRenderer.setDrawOutlines(true);
        // 设置拐点不同用不同的形状
        lineAndShapeRenderer.setBaseShapesVisible(true);
        // series 点（即数据点）间有连线可见
        lineAndShapeRenderer.setBaseLinesVisible(true);
        // 显示折点数据
        lineAndShapeRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        lineAndShapeRenderer.setBaseItemLabelsVisible(true);
        // 设置拐点不同用不同的形状
        return lineAndShapeRenderer;
    }

    /**
     * @param barRenderer 柱形图线条
     * @return
     */
    private BarRenderer setBarRenderer(BarRenderer barRenderer) {
        barRenderer.setShadowVisible(false);
        // 设置柱子宽度
        barRenderer.setMaximumBarWidth(0.05);
        // 设置柱子高度
        barRenderer.setMinimumBarLength(0.2);
        // 设置柱子边框颜色及边框可见
//        barRenderer.setBaseOutlinePaint(Color.BLACK);
//        barRenderer.setDrawBarOutline(true);
        // 设置柱的颜色
        barRenderer.setSeriesPaint(0, new Color(79, 129, 189));
        barRenderer.setSeriesPaint(1, new Color(192, 0, 0));
        // 设置每个地区所包含的平行柱的之间距离
        barRenderer.setItemMargin(0.0);
        // 显示每个柱的数值，并修改该数值的字体属性
        barRenderer.setIncludeBaseInRange(true);
        barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
//        barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}",new DecimalFormat("0.0%")));
        barRenderer.setBaseItemLabelsVisible(true);
        // 设置柱子为平面图不是立体的
        barRenderer.setBarPainter(new StandardBarPainter());

        return barRenderer;
    }

    /**
     * 判断是否存在该路径
     *
     * @param chartPath 路径
     */
    private void isChartPathExist(String chartPath) {
        File file = new File(chartPath);
        if (!file.exists()) {
            file.mkdirs();
            System.out.println("CHART_PATH=" + CHART_PATH + "create.");
        }
    }


    private JFreeChart buildChart(CategoryDataset dataSet, String chartTitle, String xName,
                                  String yName, boolean isMixture) {
        setChartTheme();
        JFreeChart chart = ChartFactory.createBarChart(chartTitle,
                xName, // 目录轴的显示标签
                yName, // 数值轴的显示标签
                dataSet, // 数据集
                PlotOrientation.VERTICAL, // 图表方向：水平、垂直
                true, // 是否显示图例(对于简单的柱状图必须是false)
                false, // 是否生成工具
                false // 是否生成URL链接
        );
        //设置标题位置
//        chart.getTitle().setPosition(RectangleEdge.RIGHT);

        chart.setTextAntiAlias(false);
        //设置坐标轴外部背景颜色
        chart.setBackgroundPaint(Color.white);

        CategoryPlot categoryPlot = chart.getCategoryPlot();
        setCategoryPlotBlack(categoryPlot);
        setNumberAxis(categoryPlot);
        setCategoryAxis(categoryPlot);
        setValueAxis(categoryPlot);
        //是否显示X轴平行的虚线
        categoryPlot.setDomainGridlinesVisible(false);

        BarRenderer barRenderer = new BarRenderer();
//         barRenderer = (BarRenderer) categoryPlot.getRenderer();
        setBarRenderer(barRenderer);
        categoryPlot.setRenderer(0, barRenderer);
        // 设置柱的透明度
        categoryPlot.setForegroundAlpha(1.0f);
        if (isMixture) {
            categoryPlot.setDataset(1, dataSet);
            //设置折线
            LineAndShapeRenderer lineAndShapeRenderer = new LineAndShapeRenderer();
            setLineRenderer(lineAndShapeRenderer);
            lineAndShapeRenderer.setBaseItemLabelsVisible(false);
            categoryPlot.setRenderer(1, lineAndShapeRenderer);
            categoryPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
        }
        return chart;
    }


    /**
     * @param charName 图标图片名称
     * @param chart    图标
     * @return 图片保存地址
     */
    public String saveFile(String charName, JFreeChart chart) {
        FileOutputStream fos_jpg = null;
        try {
            isChartPathExist(CHART_PATH);
            String chartName = CHART_PATH + charName;
            fos_jpg = new FileOutputStream(chartName);
            ChartUtilities.writeChartAsPNG(fos_jpg, chart, 809, 500, true, 10);
            return chartName;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            try {
                if (fos_jpg != null) {
                    fos_jpg.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    public static void main(String[] args) {
        JFreeChartUtil jFreeChartUtil = new JFreeChartUtil("E:\\temp\\operation\\image\\");
        double[][] data = new double[][]{{61.82, 62.91, 63.98, 66.66, 12.3, 12.4, 24.1, 35.23, 21.20, 34.44, 11.24, 12.1}, {0.6182, 0.6291, 0.6398, 0.6666, 0.123, 0.124, 0.241, 0.3523, 0.2120, 0.3444, 0.1124, 0.121}};
        double[][] data1 = new double[][]{{6182, 6291, 6398, 6666, 123, 124, 241, 3523, 2120, 3444, 1124, 121}};
        double[][] data2 = new double[][]{{0.6182, 0.6291, 0.6398, 0.6666, 0.123, 0.124, 0.241, 0.3523, 0.2120, 0.3444, 0.1124, 0.121}};

        double[][] data3 = new double[][]{{6182, 6291, 6398, 6666, 123, 124, 241, 3523, 2120, 3444, 1124, 121}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
        double[][] data4 = new double[][]{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0.6182, 0.6291, 0.6398, 0.6666, 0.123, 0.124, 0.241, 0.3523, 0.2120, 0.3444, 0.1124, 0.121}};

        String[] rowKeys = new String[]{"人数", "比例"};
        String[] rowKeys1 = new String[]{"人数"};
        String[] rowKeys2 = new String[]{"比例"};
        String[] columnKeys = {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"};
        CategoryDataset dataSet = jFreeChartUtil.getBarData(data, rowKeys, columnKeys);
        CategoryDataset dataSet1 = jFreeChartUtil.getBarData(data1, rowKeys1, columnKeys);
        CategoryDataset dataSet2 = jFreeChartUtil.getBarData(data2, rowKeys2, columnKeys);
        CategoryDataset dataSet3 = jFreeChartUtil.getBarData(data3, rowKeys, columnKeys);
        CategoryDataset dataSet4 = jFreeChartUtil.getBarData(data4, rowKeys, columnKeys);

        jFreeChartUtil.buildBarChart(dataSet, "全省用户总量（柱形图1）", "月份", "数量(万)", "userCount1.png", false);
        jFreeChartUtil.buildPairYMixtureChart(dataSet1, "全省用户总量（不同组柱形+折线）", "月份", "数量(万)", "userCount.png", dataSet2, "比例（%）");
        jFreeChartUtil.buildLineChar(dataSet, "全省用户总量（折线图）", "月份", "数量(万)", "userCountLineAndShape.jpg");
        jFreeChartUtil.buildMixtureChar(dataSet, "全省用户总量（混合图）", "月份", "数量(万)", "test.jpg");
        jFreeChartUtil.buildPairYMixtureChart(dataSet, "全省用户总量（同组折线+柱形）", "月份", "数量(万)", "userCount2.png", "比例（%）");
        jFreeChartUtil.buildPairYMixtureChart2(dataSet3, "全省用户总量（双数据）", "月份", "数量(万)", "userCount3.png", dataSet4, "比例（%）");

    }

    public NumberAxis getNumberAxis2(String y2Name, Color color) {

        NumberAxis axis2 = new NumberAxis(y2Name);
        axis2.setAxisLinePaint(color);
        axis2.setLabelPaint(color);
        axis2.setTickLabelPaint(color);
        return axis2;
    }


    //该方法不正确
    public String buildPairYMixtureChart(CategoryDataset dataSet, String chartTitle, String xName,
                                         String yName, String charName, String y2Name) {
        JFreeChart chart = this.buildChart(dataSet, chartTitle, xName, yName, false);

        Color color = new Color(192, 0, 0);
        NumberAxis axis2 = getNumberAxis2(y2Name, color);
//
//
//        BarRenderer barRenderer = new BarRenderer();
//        setBarRenderer(barRenderer);

        CategoryPlot categoryPlot = chart.getCategoryPlot();
        categoryPlot.setRangeAxis(1, axis2);
//        categoryPlot.setRenderer(1, barRenderer);
//        categoryPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
        categoryPlot.mapDatasetToDomainAxis(2, 1);

        return saveFile(charName, chart);
    }


}
